package com.supermarket_project.service.impl;

import com.supermarket_project.common.R;
import com.supermarket_project.mapper.ActivityTypeMapper;
import com.supermarket_project.pojo.Activity_Type;
import com.supermarket_project.service.ActivityTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class ActivityTypeServiceImpl implements ActivityTypeService {

    @Autowired
    ActivityTypeMapper activityTypeMapper;

    @Override
    public R addOneActivityType_s(Map activity_type_map) {
        R r=new R();
        Activity_Type activity_type=new Activity_Type();
        //设置活动类型的名称
        activity_type.setActivity_type_name(activity_type_map.get("activity_type_name").toString());
        activity_type.setDescription(Float.parseFloat(activity_type_map.get("description").toString()));
        activity_type.setStatus(Integer.parseInt(activity_type_map.get("status").toString()));
        try{
            int result=activityTypeMapper.addOneActivityType(activity_type);
            if(result==1){
                r.setCode(200);
                r.setMsg("添加活动类型成功");
                r.setData(result);
            }else{
                r.setCode(500);
                r.setMsg("添加活动类型失败");
                r.setData(result);
            }
            return r;
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统错误");
            r.setData(null);
            return r;
        }
    }

    @Override
    public R getAllActivityTypeInfo_s() {
        R r=new R();
        List<Activity_Type> result_open=null;
        List<Activity_Type> result_end=null;
        Map result=new HashMap();
        try{
            result_open=activityTypeMapper.getActivityTypeInfo_open();
            result_end=activityTypeMapper.getActivityTypeInfo_end();
            result.put("open", result_open);
            result.put("end", result_end);
            r.setCode(200);
            r.setMsg("查询所有活动类型信息成功");
            r.setData(result);
            return r;
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(500);
            r.setMsg("系统错误");
            r.setData(null);
            return r;
        }
    }
}
